﻿using System;
using System.Windows;
using System.Windows.Threading;

namespace SampleApplication
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow
	{
		public MainWindow()
		{
			InitializeComponent();
			DynamicConfigurationManager.DynamicConfigurationManager.Initialise();

			DynamicConfigurationManager.DynamicConfigurationManager.ConfigurationChanged += DynamicConfigurationManager_ConfigurationChanged;

			UpdateConfigurationText();

			//System.Threading.Timer t = new System.Threading.Timer(new System.Threading.TimerCallback(UpdateUi));
			//t.Change(0, 1000);
		}

		private void DynamicConfigurationManager_ConfigurationChanged(object sender, EventArgs e)
		{
			UpdateConfigurationText();
		}

		private void button1_Click(object sender, RoutedEventArgs e)
		{
			Close();
		}

		private void UpdateConfigurationText()
		{
			Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                   new DispatcherOperationCallback(delegate
               		{
               			try
               			{
               				output.Text = DynamicConfigurationManager.DynamicConfigurationManager.AppSettings["sampleAppSetting"];
               			}
               			catch
               			{ } // Swallow any exception here.
               			return null;
               		}), null);
		}

	}
}